package com.resource.converter;

import com.resource.request.ContractSaveRequest;
import com.resource.response.ContractDetailResponse;
import com.resource.response.ContractPageItemResponse;
import com.resource.dto.ContractSaveMainDto;
import com.resource.dto.ContractDetailDto;
import com.resource.dto.ContractPageItemDto;
import org.mapstruct.*;

/**
 * 泛微系统返回合同对象转换
 *
 * @author jianghao.zhang
 */
@Mapper(componentModel = "spring")
public interface ContractConverter {

    /**
     * ContractDetailDto 属性名称映射到 ContractDetailResponse
     *
     * @param detailDto dto
     * @return ContractDetailResponse
     */
    @Mappings({
            @Mapping(source = "field_1", target = "customerId"),
            @Mapping(source = "field_2", target = "projectId"),
            @Mapping(source = "field_3", target = "firstPartyName"),
            @Mapping(source = "field_4", target = "firstCreditCode"),
            @Mapping(source = "field_5", target = "secondPartyName"),
            @Mapping(source = "field_6", target = "secondCreditCode"),
            @Mapping(source = "field_7", target = "point"),
            @Mapping(source = "field_8", target = "firstLinkmanName"),
            @Mapping(source = "field_11", target = "validityPeriod"),
            @Mapping(source = "field_12", target = "contractStartTime"),
            @Mapping(source = "field_13", target = "contractEndTime"),
            @Mapping(source = "field_14", target = "configId"),
            @Mapping(source = "field_16", target = "businessType"),
            @Mapping(source = "field_17", target = "businessModel"),
            @Mapping(source = "field_18", target = "isLotting"),
            @Mapping(source = "field_19", target = "firstLegalRepresentative"),
            @Mapping(source = "field_20", target = "secondLegalRepresentative"),
            @Mapping(source = "field_21", target = "firstAddress"),
            @Mapping(source = "field_22", target = "secondAddress"),
            @Mapping(source = "field_23", target = "firstLinkmanEmail"),
            @Mapping(source = "field_24", target = "secondLinkmanEmail"),
            @Mapping(source = "field_25", target = "firstLinkmanPhone"),
            @Mapping(source = "field_26", target = "secondLinkmanPhone"),
            @Mapping(source = "field_27", target = "signChannel"),
            @Mapping(source = "field_28", target = "serveCompany"),
            @Mapping(source = "field_29", target = "secondLinkmanName"),
            @Mapping(source = "field_30", target = "contractStatus"),
            @Mapping(source = "field_35", target = "associationProcess"),
            @Mapping(source = "field_36", target = "contractAttachment"),
            @Mapping(source = "field_37", target = "qualificationAttachment"),
            @Mapping(source = "field_41", target = "isArchive"),
            @Mapping(source = "field_42", target = "chapterStatus"),
            @Mapping(source = "field_43", target = "contractValidityStatus"),
            @Mapping(source = "field_44", target = "archiveAttachment"),
            @Mapping(source = "user_id", target = "follower"),
            @Mapping(source = "contract_user_name", target = "followerName"),
            @Mapping(source = "type_id", target = "typeId"),
            @Mapping(source = "contract_type_name", target = "typeName"),
            @Mapping(source = "recycle_status", target = "recycleStatus"),
            @Mapping(source = "created_at", target = "createdAt"),
            @Mapping(source = "updated_at", target = "updatedAt"),
            @Mapping(source = "deleted_at", target = "deletedAt"),
    })
    ContractDetailResponse responseToDto(ContractDetailDto detailDto);

    /**
     * ContractPageItemDto 属性名称映射到 ContractPageItemResponse
     *
     * @param itemDto dto
     * @return ContractPageItemResponse
     */
    @Mappings({
            @Mapping(source = "field_1", target = "customerId"),
            @Mapping(source = "field_2", target = "projectId"),
            @Mapping(source = "field_3", target = "firstPartyName"),
            @Mapping(source = "field_4", target = "firstCreditCode"),
            @Mapping(source = "field_5", target = "secondPartyName"),
            @Mapping(source = "field_6", target = "secondCreditCode"),
            @Mapping(source = "field_7", target = "point"),
            @Mapping(source = "field_8", target = "firstLinkmanName"),
            @Mapping(source = "field_11", target = "validityPeriod"),
            @Mapping(source = "field_12", target = "contractStartTime"),
            @Mapping(source = "field_13", target = "contractEndTime"),
            @Mapping(source = "field_14", target = "configId"),
            @Mapping(source = "field_16", target = "businessType"),
            @Mapping(source = "field_17", target = "businessModel"),
            @Mapping(source = "field_18", target = "isLotting"),
            @Mapping(source = "field_19", target = "firstLegalRepresentative"),
            @Mapping(source = "field_20", target = "secondLegalRepresentative"),
            @Mapping(source = "field_21", target = "firstAddress"),
            @Mapping(source = "field_22", target = "secondAddress"),
            @Mapping(source = "field_23", target = "firstLinkmanEmail"),
            @Mapping(source = "field_24", target = "secondLinkmanEmail"),
            @Mapping(source = "field_25", target = "firstLinkmanPhone"),
            @Mapping(source = "field_26", target = "secondLinkmanPhone"),
            @Mapping(source = "field_27", target = "signChannel"),
            @Mapping(source = "field_28", target = "serveCompany"),
            @Mapping(source = "field_29", target = "secondLinkmanName"),
            @Mapping(source = "field_30", target = "contractStatus"),
            @Mapping(source = "field_35", target = "associationProcess"),
            @Mapping(source = "field_36", target = "contractAttachment"),
            @Mapping(source = "field_37", target = "qualificationAttachment"),
            @Mapping(source = "field_41", target = "isArchive"),
            @Mapping(source = "field_42", target = "chapterStatus"),
            @Mapping(source = "field_43", target = "contractValidityStatus"),
            @Mapping(source = "field_44", target = "archiveAttachment"),
            @Mapping(source = "user_id", target = "follower"),
            @Mapping(source = "main_id", target = "mainId"),
    })
    ContractPageItemResponse responseToPageDto(ContractPageItemDto itemDto);

    /**
     * ContractSaveRequest 属性名称映射到 ContractSaveMainDto
     *
     * @param saveRequest request
     * @return ContractSaveMainDto
     */
    @Mappings({
            @Mapping(source = "customerId", target = "field_1"),
            @Mapping(source = "projectId", target = "field_2"),
            @Mapping(source = "firstPartyName", target = "field_3"),
            @Mapping(source = "firstCreditCode", target = "field_4"),
            @Mapping(source = "secondPartyName", target = "field_5"),
            @Mapping(source = "secondCreditCode", target = "field_6"),
            @Mapping(source = "point", target = "field_7"),
            @Mapping(source = "firstLinkmanName", target = "field_8"),
            @Mapping(source = "validityPeriod", target = "field_11"),
            @Mapping(source = "contractStartTime", target = "field_12"),
            @Mapping(source = "contractEndTime", target = "field_13"),
            @Mapping(source = "configId", target = "field_14"),
            @Mapping(source = "businessType", target = "field_16"),
            @Mapping(source = "businessModel", target = "field_17"),
            @Mapping(source = "isLotting", target = "field_18"),
            @Mapping(source = "firstLegalRepresentative", target = "field_19"),
            @Mapping(source = "secondLegalRepresentative", target = "field_20"),
            @Mapping(source = "firstAddress", target = "field_21"),
            @Mapping(source = "secondAddress", target = "field_22"),
            @Mapping(source = "firstLinkmanEmail", target = "field_23"),
            @Mapping(source = "secondLinkmanEmail", target = "field_24"),
            @Mapping(source = "firstLinkmanPhone", target = "field_25"),
            @Mapping(source = "secondLinkmanPhone", target = "field_26"),
            @Mapping(source = "signChannel", target = "field_27"),
            @Mapping(source = "serveCompany", target = "field_28"),
            @Mapping(source = "secondLinkmanName", target = "field_29"),
            @Mapping(source = "contractStatus", target = "field_30"),
            @Mapping(source = "associationProcess", target = "field_35"),
            @Mapping(source = "contractAttachment", target = "field_36"),
            @Mapping(source = "qualificationAttachment", target = "field_37"),
            @Mapping(source = "isArchive", target = "field_41"),
            @Mapping(source = "chapterStatus", target = "field_42"),
            @Mapping(source = "contractValidityStatus", target = "field_43"),
            @Mapping(source = "archiveAttachment", target = "field_44"),
            @Mapping(source = "typeId", target = "type_id"),
            @Mapping(source = "follower", target = "user_id"),
            @Mapping(source = "mainId", target = "main_id"),
    })
    ContractSaveMainDto requestToAddDto(ContractSaveRequest saveRequest);
}
